/**
 * 
 */
package au.edu.swin.videoshop.persistence;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author julie
 *
 */
@Entity
@NamedQueries({
	@NamedQuery (
			name="cancelReservation", 
			query="UPDATE ReservationEntity r SET r.status='Cancelled' WHERE r.customer.customerId=:customerId AND r.reservationId=:reservationId"
	),
	@NamedQuery (
			name="findReservationsByCustomerId", 
			query="SELECT r FROM ReservationEntity r WHERE r.customer.customerId=:customerId AND r.status='Open'"
	)
})
@Table(name="RESERVATION")
public class ReservationEntity implements Serializable{
	private Long mReservationId;
	private TitleMediumEntity mMedium;
	private StoreEntity mStore;
	private CustomerEntity mCustomer;
	private Date mReservationDate;
	private Date mExpiryDate;
	private String mStatus;
	
	/**
	 * @return the reservationId
	 */
	@Id
	@GeneratedValue (strategy=GenerationType.AUTO)
	@Column(name="RESERVATION_ID")
	public Long getReservationId() {
		return mReservationId;
	}
	
	/**
	 * @param reservationId the reservationId to set
	 */
	public void setReservationId(Long reservationId) {
		mReservationId = reservationId;
	}
	
	/**
	 * @return the medium
	 */
	@ManyToOne(optional=false, fetch=FetchType.EAGER)
	@JoinColumn(name="TITLE_MEDIUM_ID")
	public TitleMediumEntity getMedium() {
		return mMedium;
	}
	
	/**
	 * @param medium the medium to set
	 */
	public void setMedium(TitleMediumEntity medium) {
		mMedium = medium;
	}
	
	/**
	 * @return the store
	 */
	@ManyToOne(optional=false, fetch=FetchType.EAGER)
	@JoinColumn(name="STORE_ID")
	public StoreEntity getStore() {
		return mStore;
	}
	
	/**
	 * @param store the store to set
	 */
	public void setStore(StoreEntity store) {
		mStore = store;
	}
	
	/**
	 * @return the customer
	 */
	@ManyToOne(optional=false, fetch=FetchType.EAGER)
	@JoinColumn(name="CUSTOMER_ID")
	public CustomerEntity getCustomer() {
		return mCustomer;
	}
	
	/**
	 * @param customer the customer to set
	 */
	public void setCustomer(CustomerEntity customer) {
		mCustomer = customer;
	}
	
	/**
	 * @return the reservationDate
	 */
	@Column(name="RESERVATION_DATE")
	@Temporal(value=TemporalType.DATE)
	public Date getReservationDate() {
		return mReservationDate;
	}
	
	/**
	 * @param reservationDate the reservationDate to set
	 */
	public void setReservationDate(Date reservationDate) {
		mReservationDate = reservationDate;
	}
	
	/**
	 * @return the expiryDate
	 */
	@Column(name="EXPIRY_DATE")
	@Temporal(value=TemporalType.DATE)
	public Date getExpiryDate() {
		return mExpiryDate;
	}
	
	/**
	 * @param expiryDate the expiryDate to set
	 */
	public void setExpiryDate(Date expiryDate) {
		mExpiryDate = expiryDate;
	}
	
	/**
	 * @return the status
	 */
	@Column(name="RESERVATION_STATUS")
	public String getStatus() {
		return mStatus;
	}
	
	/**
	 * @param status the status to set
	 */
	public void setStatus(String status) {
		mStatus = status;
	}
	
	
}
